package dinghan.workflow.kq.service.impl;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import dinghan.workflow.kq.entity.JiaBanAppDT;
import dinghan.workflow.kq.service.JiabanDetailService;
import weaver.conn.RecordSet;

public class JiaBanServiceImpl extends KQDetailBaseImpl<JiaBanAppDT> implements JiabanDetailService{

	private static final String formName = "formtable_main_94_dt1";	//表名
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	/**
	 * 新增加班明细   -- 暂不开放
	 */
	/*
	public void add(JiaBanAppDT jiaBanAppDT){
		
		RecordSet rs = new RecordSet();
		
		String sql = "insert into " + formName + " (mainid,jbrq,sfztx,hdkssj,hdjssj,xxsj,yxgs,jbxs,hdgs,yjkssj,yjjssj,xq,dkjl,hdzt)"
				+ " values("
						+ "'" + jiaBanAppDT.getMainid() + "'"
							+ ",'" + jiaBanAppDT.getJbrq() + "'"
								+ ",'" + jiaBanAppDT.getSfztx() + "'"
									+ ",'" + jiaBanAppDT.getHdkssj() + "'"
										+ ",'" + jiaBanAppDT.getHdjssj() + "'"
											+ ",'" + jiaBanAppDT.getXxsj() + "'"
												+ ",'" + jiaBanAppDT.getYxgs() + "'"
													+ ",'" + jiaBanAppDT.getJbxs() + "'"
														+ ",'" + jiaBanAppDT.getHdgs() + "'"
															+ ",'" + jiaBanAppDT.getYjkssj() + "'"
																+ ",'" + jiaBanAppDT.getYjjssj() + "'"
																	+ ",'" + jiaBanAppDT.getXq() + "'"
																		+ ",'" + jiaBanAppDT.getDkjl() + "'"
																			+ ",'" + jiaBanAppDT.getHdzt() + "'"
																				+ ")";
		
		rs.executeSql(sql);
		
	}*/
	
	/**
	 * 更新加班明细表
	 */
	public void update(JiaBanAppDT jiaBanAppDT){
		
		RecordSet rs = new RecordSet();
		
		String sql = "update " + formName + " set jbrq = '"+ jiaBanAppDT.getJbrq() +"',"
				+ "sfztx = '"+jiaBanAppDT.getSfztx()+"'"
						+ ",hdkssj = '"+jiaBanAppDT.getHdkssj()+"'"
								+ ",hdjssj = '"+jiaBanAppDT.getHdjssj()+"'"
										+ ",xxsj = '"+jiaBanAppDT.getXxsj()+"'"
												+ ",yxgs = '"+jiaBanAppDT.getYxgs()+"'"
														+ ",jbxs = '"+jiaBanAppDT.getJbxs()+"'"
																+ ",hdgs = '"+jiaBanAppDT.getHdgs()+"'"
																		+ ",yjkssj = '"+jiaBanAppDT.getYjkssj()+"'"
																				+ ",yjjssj = '"+jiaBanAppDT.getYjjssj()+"'"
																						+ ",xq = '"+jiaBanAppDT.getXq()+"'"
																								+ ",dkjl = '"+jiaBanAppDT.getDkjl()+"'"
																										+ ",hdzt = '" +jiaBanAppDT.getHdzt()+ "'";
		
		rs.executeSql(sql);
		
	}
	
	/**
	 * 通过ID获取加班申请明细表实体化对象
	 * @author zhangxiaoyu(10593) -- 创建时间 2017.4.8 
	 * @param id -- 加班明细表id (*非mainid)
	 */
	@Override
	public JiaBanAppDT queryById(int id) {
		JiaBanAppDT jiaBanAppDT = null;
		String sql = "select top 1 * from " + formName + " where id = " + id;
		
		RecordSet rs = new RecordSet();
		
		rs.executeSql(sql);
		
		while(rs.next()){
			jiaBanAppDT = new JiaBanAppDT();
			
			jiaBanAppDT.setId(rs.getInt("id"));
			jiaBanAppDT.setMainid(rs.getInt("mainid"));
			jiaBanAppDT.setJbrq(rs.getString("jbrq"));	
			jiaBanAppDT.setXq(rs.getString("xq"));	//星期
			jiaBanAppDT.setSfztx(rs.getInt("sfztx"));		//是否转调休
			jiaBanAppDT.setYjkssj(rs.getString("yjkssj"));	//预计开始时间
			jiaBanAppDT.setYjjssj(rs.getString("yjjssj"));	//预计结束时间
			
			jiaBanAppDT.setHdkssj(rs.getString("hdkssj"));	//核定开始时间
			jiaBanAppDT.setHdjssj(rs.getString("hdjssj"));	//核定结束时间
			
			jiaBanAppDT.setXxsj(rs.getDouble("xxsj")); //休息时数
			jiaBanAppDT.setYxgs(rs.getDouble("yxgs")); //有效工时
			jiaBanAppDT.setJbxs(rs.getDouble("jbxs"));	//加班系数
			jiaBanAppDT.setHdgs(rs.getDouble("hdgs"));	//核定工时 -- 有效工时 * 加班系数
			
			jiaBanAppDT.setHdzt(rs.getInt("hdzt"));	//核定状态
			
			jiaBanAppDT.setDkjl(rs.getString("dkjl"));	//打卡记录
			
		}
		
		return jiaBanAppDT;
	}
	/*
	
	 * 用于获取加班明细列表
	 * @param mainID -- 明细对应的主表ID
	 *
	public List<JiaBanAppDT> queryListByMainID(int mainID) {
		
		List<JiaBanAppDT> jiabanAppTDList = new ArrayList<JiaBanAppDT>();
		
		String sql_list = "select from " + formName + " where mainid = " + mainID;
		
		RecordSet rs = new RecordSet();
		
		rs.executeSql(sql_list);
		
		while(rs.next()){
			JiaBanAppDT jiaBanAppDT = new JiaBanAppDT();
			
			jiaBanAppDT.setId(rs.getInt("id"));
			jiaBanAppDT.setMainid(rs.getInt("mainid"));
			jiaBanAppDT.setJbrq(rs.getString("jbrq"));	
			jiaBanAppDT.setXq(rs.getString("xq"));	//星期
			jiaBanAppDT.setSfztx(rs.getInt("sfztx"));		//是否转调休
			jiaBanAppDT.setYjkssj(rs.getString("yjkssj"));	//预计开始时间
			jiaBanAppDT.setYjjssj(rs.getString("yjjssj"));	//预计结束时间
			
			jiaBanAppDT.setHdkssj(rs.getString("hdkssj"));	//核定开始时间
			jiaBanAppDT.setHdjssj(rs.getString("hdjssj"));	//核定结束时间
			
			jiaBanAppDT.setXxsj(rs.getDouble("xxsj")); //休息时数
			jiaBanAppDT.setYxgs(rs.getDouble("yxgs")); //有效工时
			jiaBanAppDT.setJbxs(rs.getDouble("jbxs"));	//加班系数
			jiaBanAppDT.setHdgs(rs.getDouble("hdgs"));	//核定工时 -- 有效工时 * 加班系数
			
			jiaBanAppDT.setHdzt(rs.getInt("hdzt"));	//核定状态
			
			jiaBanAppDT.setDkjl(rs.getString("dkjl"));	//打卡记录
			
			jiabanAppTDList.add(jiaBanAppDT);
		}
		
		return jiabanAppTDList;
	}
	*/

	@Override
	public List<JiaBanAppDT> queryListBySEDate(String startDate, String endDate) {
		
		List<JiaBanAppDT> jiabanAppTDList = new ArrayList<JiaBanAppDT>();
		
		String sql_list = "select from " + formName + " where jbrq <= '" + endDate + "'"
				+ " and jbrq >= '" + startDate + "' order by jbrq";
		
		RecordSet rs = new RecordSet();
		
		rs.executeSql(sql_list);
		
		while(rs.next()){
			JiaBanAppDT jiaBanAppDT = new JiaBanAppDT();
			
			jiaBanAppDT.setId(rs.getInt("id"));
			jiaBanAppDT.setMainid(rs.getInt("mainid"));
			jiaBanAppDT.setJbrq(rs.getString("jbrq"));	
			jiaBanAppDT.setXq(rs.getString("xq"));	//星期
			jiaBanAppDT.setSfztx(rs.getInt("sfztx"));		//是否转调休
			jiaBanAppDT.setYjkssj(rs.getString("yjkssj"));	//预计开始时间
			jiaBanAppDT.setYjjssj(rs.getString("yjjssj"));	//预计结束时间
			
			jiaBanAppDT.setHdkssj(rs.getString("hdkssj"));	//核定开始时间
			jiaBanAppDT.setHdjssj(rs.getString("hdjssj"));	//核定结束时间
			
			jiaBanAppDT.setXxsj(rs.getDouble("xxsj")); //休息时数
			jiaBanAppDT.setYxgs(rs.getDouble("yxgs")); //有效工时
			jiaBanAppDT.setJbxs(rs.getDouble("jbxs"));	//加班系数
			jiaBanAppDT.setHdgs(rs.getDouble("hdgs"));	//核定工时 -- 有效工时 * 加班系数
			
			jiaBanAppDT.setHdzt(rs.getInt("hdzt"));	//核定状态
			
			jiaBanAppDT.setDkjl(rs.getString("dkjl"));	//打卡记录
			
			jiabanAppTDList.add(jiaBanAppDT);
		}
		
		return jiabanAppTDList;
	}
}
